import * as CONSTANT from './constatns'
import axios from 'axios'
import { fromJS } from 'immutable'

//返回一个action对象
export const searchonFocus = () => ({
    type : CONSTANT.SEARCHONFOCUS
})

export const searchonBlur = () => ({
    type : CONSTANT.SEARCHONBLUR
})


const setlistdata = (data)=>({
    type : CONSTANT.GETSEARCHLIST,
    list : fromJS(data)
})

//使用thunk之后actionCreatros可以返回一个方法 dispatch为参数
export const getdatalist = () => {
    return (dispatch) => {
        axios.get('/api/list.json').then((res)=>{
            const data = res.data.data
            dispatch(setlistdata(data))
        }).catch( ()=>{
            console.log('error');
    })
    }
}